package Hibernate.dao;

import java.util.List;

import org.hibernate.LockOptions;
import org.hibernate.Query;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MobileAdministrator entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see Hibernate.dao.MobileAdministrator
 * @author MyEclipse Persistence Tools
 */
public class MobileAdministratorDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MobileAdministratorDAO.class);
	// property constants
	public static final String ADMIN_PSD = "adminPsd";
	public static final String EPNAME = "epname";

	public void save(MobileAdministrator transientInstance) {
		log.debug("saving MobileAdministrator instance");
		Transaction tr = getSession().beginTransaction();
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
			tr.commit();
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}finally{
			getSession().flush();
			getSession().close();
		}
	}

	public void delete(MobileAdministrator persistentInstance) {
		log.debug("deleting MobileAdministrator instance");
		Transaction tr = getSession().beginTransaction();
		try {
			getSession().delete(persistentInstance);
			tr.commit();
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}finally{
			getSession().flush();
			getSession().close();
		}
	}

	public MobileAdministrator findById(java.lang.String id) {
		log.debug("getting MobileAdministrator instance with id: " + id);
		Transaction tr = getSession().beginTransaction();
		try {
			MobileAdministrator instance = (MobileAdministrator) getSession()
					.get("Hibernate.dao.MobileAdministrator", id);
			tr.commit();
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}finally{
			getSession().flush();
			getSession().close();
		}
	}

	public List findByExample(MobileAdministrator instance) {
		log.debug("finding MobileAdministrator instance by example");
		Transaction tr = getSession().beginTransaction();
		try {
			List results = getSession()
					.createCriteria("Hibernate.dao.MobileAdministrator")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			tr.commit();
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}finally{
			getSession().flush();
			getSession().close();
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MobileAdministrator instance with property: "
				+ propertyName + ", value: " + value);
		Transaction tr = getSession().beginTransaction();
		try {
			String queryString = "from MobileAdministrator as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			tr.commit();
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}finally{
			getSession().flush();
			getSession().close();
		}
	}

	public List findByAdminPsd(Object adminPsd) {
		return findByProperty(ADMIN_PSD, adminPsd);
	}

	public List findByEpname(Object epname) {
		return findByProperty(EPNAME, epname);
	}

	public List findAll() {
		log.debug("finding all MobileAdministrator instances");
		Transaction tr = getSession().beginTransaction();
		try {
			String queryString = "from MobileAdministrator";
			Query queryObject = getSession().createQuery(queryString);
			tr.commit();
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}finally{
			getSession().flush();
			getSession().close();
		}
	}

	public MobileAdministrator merge(MobileAdministrator detachedInstance) {
		log.debug("merging MobileAdministrator instance");
		try {
			MobileAdministrator result = (MobileAdministrator) getSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MobileAdministrator instance) {
		log.debug("attaching dirty MobileAdministrator instance");
		Transaction tr = getSession().beginTransaction();
		try {
			getSession().saveOrUpdate(instance);
			tr.commit();
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}finally{
			getSession().flush();
			getSession().close();
		}
	}

	public void attachClean(MobileAdministrator instance) {
		log.debug("attaching clean MobileAdministrator instance");
		try {
			getSession().buildLockRequest(LockOptions.NONE).lock(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}